package com.adley.es.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;

@Configuration
@EnableElasticsearchRepositories(basePackages = {"com.adley.es.es.repo"})
public class EsConfig {
    @Autowired
    private Environment env;

    @Bean
    public RestHighLevelClient client() {

      ClientConfiguration clientConfiguration = ClientConfiguration.builder() 
        .connectedTo(env.getProperty("es.cluster.url"))
        .build();

      return RestClients.create(clientConfiguration).rest();
    }
}
